using System;
namespace APP.HELPER.Utils.BarcodeLib
{
	internal class UPCSupplement2 : BarcodeCommon, IBarcode
	{
		private string[] EAN_CodeA = new string[]
		{
			"0001101",
			"0011001",
			"0010011",
			"0111101",
			"0100011",
			"0110001",
			"0101111",
			"0111011",
			"0110111",
			"0001011"
		};
		private string[] EAN_CodeB = new string[]
		{
			"0100111",
			"0110011",
			"0011011",
			"0100001",
			"0011101",
			"0111001",
			"0000101",
			"0010001",
			"0001001",
			"0010111"
		};
		private string[] UPC_SUPP_2 = new string[]
		{
			"aa",
			"ab",
			"ba",
			"bb"
		};
		public string Encoded_Value
		{
			get
			{
				return this.Encode_UPCSupplemental_2();
			}
		}
		public UPCSupplement2(string input)
		{
			this.Raw_Data = input;
		}
		private string Encode_UPCSupplemental_2()
		{
			if (this.Raw_Data.Length != 2)
			{
				throw new Exception("EUPC-SUP2-1: Invalid data length. (Length = 2 required)");
			}
			if (!BarcodeEdit.CheckNumericOnly(this.Raw_Data))
			{
				throw new Exception("EUPC-SUP2-2: Numeric Data Only");
			}
			string text = "";
			try
			{
				text = this.UPC_SUPP_2[int.Parse(this.Raw_Data.Trim()) % 4];
			}
			catch
			{
				throw new Exception("EUPC-SUP2-3: Invalid Data. (Numeric only)");
			}
			string text2 = "1011";
			int index = 0;
			string text3 = text;
			for (int i = 0; i < text3.Length; i++)
			{
				char c = text3[i];
				if (c == 'a')
				{
					text2 += this.EAN_CodeA[int.Parse(this.Raw_Data[index].ToString())];
				}
				else
				{
					if (c == 'b')
					{
						text2 += this.EAN_CodeB[int.Parse(this.Raw_Data[index].ToString())];
					}
				}
				if (index++ == 0)
				{
					text2 += "01";
				}
			}
			return text2;
		}
	}
}
